#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e5 + 10;
int dp[maxn];
int diff[maxn][7];// diff[i][k] :从i位置往前的k个字符片段的记忆难度

void cal(string s, int n) {

  for (int i = 3; i <= n; i++) {
    if (s[i] - s[i - 1] == s[i - 1] - s[i - 2]) {
      if (s[i] - s[i - 1] == 0)
        diff[i][3] = 1;
      else if (s[i] - s[i - 1] == 1 || s[i] - s[i - 1] == -1)
        diff[i][3] = 2;
      else
        diff[i][3] = 5;
    } else {
      if (s[i] == s[i - 2])
        diff[i][3] = 4;
      else
        diff[i][3] = 10;
    }
  }
  for (int k = 4; k <= 6; k++) {
    for (int i = 4; i <= n; i++) {
      if (diff[i - 1][k - 1] == 1 && s[i] == s[i - 1])
        diff[i][k] = 1;
      else if (diff[i - 1][k - 1] == 2 &&
               s[i] - s[i - 1] == s[i - 1] - s[i - 2])
        diff[i][k] = 2;
      else if (diff[i - 1][k - 1] == 5 &&
               s[i] - s[i - 1] == s[i - 1] - s[i - 2])
        diff[i][k] = 5;
      else if (diff[i - 1][k - 1] == 4 && s[i] == s[i - 2])
        diff[i][k] = 4;
      else
        diff[i][k] = 10;
    }
  }
}
int main() {
  string s;
  cin >> s;
  int n = s.size();
  s = '0' + s;
  cal(s, n);
  memset(dp, 0x3f3f3f3f, sizeof(dp));
  dp[0] = 0;
  for (int i = 3; i <= n; i++) {
    for (int k = 3; k <= 6; k++) {
      //防止i-k越界
      if (i - k < 0)
        continue;
      dp[i] = min(dp[i], dp[i - k] + diff[i][k]); //状态转移方程
    }
    // cout << i << " " << dp[i] << endl;
  }

  cout << dp[n];
  return 0;
}